(function () {
    var address = "http://localhost:81/html/index.html";
    var url = "http://localhost:81/api";
    $("#btn1").on("click", function () {
        $.ajax({
            type: "get",
            url: url,
            data: {
                type: "login",
                user: $("#user").val(),
                pass: $("#pass1").val(),
            },
            success: (res) => {
                let rest = JSON.parse(res);
                console.log(rest)
                if (rest.code === 400) {
                    alert("登录成功");

                    if ($("#remberpass")[0].checked === true) {
                        rest.data.onoff = true
                    } else {
                        rest.data.onoff = false
                    }
                    let userMsg = JSON.stringify(rest.data)
                    $.cookie(rest.data.user, userMsg, {
                        expires: 7
                    })
                    $.cookie("loadsuccess", rest.data.user)
                    window.location.href = address
                }
                if (rest.code === 0) {
                    $("#user").next().html(`${rest.msg}前往<a href="http://localhost:81/html/register.html" id="register">注册</a>`)
                }
                if (rest.code === 2) {
                    $("#pass1").next().text(rest.msg)

                }
            },
        });
    });
})();

//渲染页尾
(function () {
    $(".login_load_footer").load(
        "http://localhost:81/html/public.html .footer_wrap"
    );
    $(".login_load_bottom").load(
        "http://localhost:81/html/public.html .bottom_wrap"
    );
})();

//判断是否记住密码
(function () {
    $("#user").on("change", function () {
        if ($.cookie($("#user").val()) !== null) {
            if (JSON.parse($.cookie($("#user").val())).onoff) {
                $("#pass1").val(JSON.parse($.cookie($("#user").val())).pass)
            }
        }
    })
})()